﻿Imports System.Data.OleDb
Public Class frmMain
    Private Sub mnuExit_Click(sender As System.Object, e As System.EventArgs) Handles mnuExit.Click
        Me.Close()
    End Sub

    Private Sub mnuAddNewAppointmentSummary_Click(sender As System.Object, e As System.EventArgs) Handles mnuAddNewAppointmentSummary.Click
        frmAppointments.Show()
        Me.Close()
    End Sub

    Private Sub mnuDisplayAppointmentSummary_Click(sender As System.Object, e As System.EventArgs) Handles mnuDisplayAppointmentSummary.Click

        'Part 1: Check if Table is Empty.

        Dim connection As OleDb.OleDbConnection
        Dim mydb, mystr As String

        mystr = ("Provider=Microsoft.JET.OLEDB.4.0;" & _
                 "Data Source=|DataDirectory|\Decisions.mdb")

        connection = New OleDb.OleDbConnection(mystr)

        connection.Open()

        mydb = "SELECT COUNT(*) FROM tblDecisions"

        Dim run = New OleDb.OleDbCommand

        run = New OleDbCommand(mydb, connection)


        Dim DataReader As OleDbDataReader

        DataReader = run.ExecuteReader() 'Populate the reader

        While (DataReader.Read())

            If DataReader(0).ToString() = 0 Then

                'Loop all the records

                MessageBox.Show("There are no Appointments added yet.")

                frmAppointments.Show()
                Me.Close()

            Else

                'Part 2: List items in table.

                'Load new form
                frmDisplayAppointments.Show()

                'Clears ListView before it is populated
                frmDisplayAppointments.ListViewDisplayAppointments.Items.Clear()

                'Populates ListView from Access Database
                Try
                    PopulateListViewFromAccess(frmDisplayAppointments.ListViewDisplayAppointments)
                Catch ex As Exception
                    MessageBox.Show(ex.ToString())
                End Try

                'Close current form
                Me.Close()

            End If

        End While

        '------------------------------------

        'Close connection
        'connection.Close()

    End Sub

    Private Sub mnuAbout_Click(sender As System.Object, e As System.EventArgs) Handles mnuAbout.Click
        frmAbout.Show()
    End Sub
End Class
